
foreach smpl in log_log log_linear linear linear_trimmed  {
	
	foreach prd in POS PPO {

		use "$temp\reg_coeffs_`prd'_all years_`smpl'.dta", clear
		if `smpl' == `log-log' {
			keep if var == "ln_wtp" | var == "_cons"
		}
		
		else {
			keep if var == "wtp_pp" | var == "_cons"
		}
		
		replace var = cons if var == "_cons"
		keep var coef analysis_area
		reshape wide coef, i(analysis_area) j(var) str
		ren coef* coef_* 
		save "$temp\lhs_coeffs_`prd'.dta", replace
			
			use "$temp\cbsa_`prd'_all years.dta", clear
			
			gen rec_cnt = 1
			bysort analysis_area yr: egen tot_ipdays = total(ipdtot)
			gen bed_days = bdtot*365
			bysort analysis_area yr: egen tot_beddays = total(bed_days)
			gen hosp_util = tot_ipdays/tot_beddays 
			gen out_shr = area_out_pts/area_pts
			collapse (sum) rec_cnt (mean) hosp_util cbsa_ins_hhi pct_lt200pl pct_unins area_pts, by(analysis_area prod) fast
			
			merge m:1 analysis_area using "$temp\lhs_coeffs_`prd'.dta"
			drop if _m == 1

			gen ihhi = cbsa_ins_hhi/10000
			gen pop = co_tot_pop/1000
			gen ppo = prod=="PPO"
			
			save "$temp\reg_input_`prd'_4 yr avg_`smpl'.dta", replace
	}

use "$temp\reg_input_POS_4 yr avg_`smpl'.dta", clear
append using "$temp\reg_input_PPO_4 yr avg_`smpl'.dta"

	if `smpl' == `log-log' {

		*WTP
		reg coef_ln_wtp ihhi i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_ln_wtp ihhi pct_lt200pl i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_ln_wtp ihhi pct_unins i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_ln_wtp ihhi hosp_util i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_ln_wtp ihhi pct_lt200pl hosp_util i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_ln_wtp ihhi pct_unins hosp_util i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_ln_wtp ihhi pct_lt200pl pct_unins hosp_util i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

	}

	else {

		*WTP
		reg coef_wtp_pp ihhi i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_wtp_pp ihhi pct_lt200pl i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_wtp_pp ihhi pct_unins i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_wtp_pp ihhi hosp_util i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_wtp_pp ihhi pct_lt200pl hosp_util i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_wtp_pp ihhi pct_unins hosp_util i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

		reg coef_wtp_pp ihhi pct_lt200pl pct_unins hosp_util i.ppo, vce(robust)
		outreg2 using "$exp\WTP-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(WTP, Robust SE)

	}

	*Constant
	reg coef_cons ihhi i.ppo, vce(robust)
	outreg2 using "$exp\Constant-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(Const, Robust SE)
		
	reg coef_cons ihhi pct_lt200pl i.ppo, vce(robust)
	outreg2 using "$exp\Constant-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(Const, Robust SE)

	reg coef_cons ihhi pct_unins i.ppo, vce(robust)
	outreg2 using "$exp\Constant-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(Const, Robust SE)
		
	reg coef_cons ihhi hosp_util i.ppo, vce(robust)
	outreg2 using "$exp\Constant-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(Const, Robust SE)

	reg coef_cons ihhi pct_lt200pl hosp_util i.ppo, vce(robust)
	outreg2 using "$exp\Constant-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(Const, Robust SE)

	reg coef_cons ihhi pct_unins hosp_util i.ppo, vce(robust)
	outreg2 using "$exp\Constant-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(Const, Robust SE)

	reg coef_cons ihhi pct_lt200pl pct_unins hosp_util i.ppo, vce(robust)
	outreg2 using "$exp\Constant-Avg market chars regs_`smpl'_`d'.xls", adjr2 ctitle(Const, Robust SE)

}

exit
